﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace ClassLibrary1 {

    class Udp {
        static void ConnectCompleted(object sender, SocketAsyncEventArgs e) {
        }


        static void _Main(string[] args) {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            //socket.Blocking = true;
            socket.Bind(new IPEndPoint(IPAddress.Any, 0));
            SocketAsyncEventArgs e = new SocketAsyncEventArgs();
            e.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("192.168.168.182"), 53);
            e.Completed += new EventHandler<SocketAsyncEventArgs>(ConnectCompleted);
            
            if (!socket.ConnectAsync(e)) {
                if (e.SocketError != SocketError.Success) {
                    System.Console.Error.WriteLine("connect failed: " + e.SocketError);
                    return;
                }
            }


            System.Console.Out.WriteLine("connect succeeded");
            return;
        }
    }
}
